package com.clayecloud.common.config;

import com.clayecloud.common.interceptor.TokenInterceptor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.annotation.Resource;

@Configuration
public class WebConfig implements WebMvcConfigurer {

    @Resource
    private TokenInterceptor tokenInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        String[] excludePatterns = { //不拦截的请求
                "/doc.html",
                "/swagger-resources",
                "/v2/api-docs"
        };
        registry.addInterceptor(this.tokenInterceptor).addPathPatterns("/**").excludePathPatterns(excludePatterns);
        WebMvcConfigurer.super.addInterceptors(registry);
    }
}
